package com.cout970.magneticraft.features

import com.cout970.magneticraft.misc.RegisterTileEntity
import com.cout970.magneticraft.misc.block.getFacing
import com.cout970.magneticraft.misc.block.getOrientation
import com.cout970.magneticraft.misc.block.getOrientationCentered
import com.cout970.magneticraft.misc.inventory.Inventory
import com.cout970.magneticraft.misc.tileentity.DoNotRemove
import com.cout970.magneticraft.misc.tileentity.TimeCache
import com.cout970.magneticraft.misc.tileentity.shouldTick
import com.cout970.magneticraft.misc.vector.*
import com.cout970.magneticraft.registry.getOrNull
import com.cout970.magneticraft.systems.config.Config
import com.cout970.magneticraft.systems.tileentities.TileBase
import com.cout970.magneticraft.systems.tilemodules.*
import net.minecraft.block.Block
import net.minecraft.util.EnumFacing
import net.minecraft.util.ITickable
import net.minecraft.util.math.AxisAlignedBB
import net.minecraftforge.fluids.FluidRegistry
import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.capability.IFluidHandler

/**
 * Created by cout970 on 2017/08/10.
 */

open class TileBaseInserter(val hasSpeedUpgrade: Boolean, val hasStackUpgrade: Boolean) : TileBase(), ITickable {
    val facing: EnumFacing get() = getBlockState().getOrientation()
    val filters = Inventory(9)
    val inventory: Inventory = Inventory(1)
    val invModule = ModuleInventory(inventory, capabilityFilter = { null })
    val openGui = ModuleOpenGui()
    val inserterModule = ModuleInserter({ facing }, inventory, filters, hasSpeedUpgrade, hasStackUpgrade)

    init {
        initModules(inserterModule, invModule, openGui)
    }

    @DoNotRemove
    override fun update() {
        super.update()
    }
}

open class TileBaseConveyor : TileBase(), ITickable {
    val facing: EnumFacing get() = getBlockState().getOrientation()
    val conveyorModule = ModuleConveyor({ facing })

    init {
        initModules(conveyorModule)
    }

    @DoNotRemove
    override fun update() {
        super.update()
    }

    override fun getRenderBoundingBox(): AxisAlignedBB {
        return pos createAABBUsing pos.add(1, 2, 1)
    }
}

@RegisterTileEntity("conveyor_lvl0")
class TileConveyorLvl0 : TileBaseConveyor() {}

@RegisterTileEntity("inserter_lvl0")
class TileInserterLvl0 : TileBaseInserter(false, false) {}
@RegisterTileEntity("inserter_lvl1")
class TileInserterLvl1 : TileBaseInserter(true,  false) {}
@RegisterTileEntity("inserter_lvl2")
class TileInserterLvl2 : TileBaseInserter(false, true ) {}
@RegisterTileEntity("inserter_lvl3")
class TileInserterLvl3 : TileBaseInserter(true,  true ) {}
